package com.demo.core.service.base.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo.core.dao.FunctionDao;
import com.demo.core.dao.base.support.ResultSearchResult;
import com.demo.core.dao.base.support.SearchArgumentSupport;
import com.demo.core.model.Function;
import com.demo.core.service.base.FunctionService;
/**
 * 功能服务实现类
 * @author ryuu.kk
 *
 */
public class FunctionServiceImpl implements FunctionService {
	/**
	 * 功能模型数据访问层
	 */
	private FunctionDao functionDao;
	
	@Override
	public Long save(Function function) {
		return functionDao.insert(function);
	}
	@Override
	public boolean exist(Long id) {
		return functionDao.exists(id);
	}
	@Override
	public void delete(Long functionId) {
		functionDao.delete(functionId);
	}

	@Override
	public void update(Long id, Function function) {
		Map<String, Object> params = new HashMap<String, Object>(2);
		params.put("id", id);
		functionDao.update(function, params);
	}

	@Override
	public Function find(Long id) {
		return functionDao.select(id);
	}

	@Override
	public List<Function> findList(Long siteGroupId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("siteGroupId", siteGroupId);
		return functionDao.select(params);
	}
	
	@Override
	public List<Function> findList(String type) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("type", type);
		return functionDao.select(params);
	}
	
	@Override
	public List<Function> query(Long id) {
		return functionDao.query(id);
	}
	
	@Override
	public List<Function> query(Long id, Long siteGroupId) {
		return functionDao.query(id, siteGroupId);
	}
	
	@Override
	public Function tree(Long id) {
		return tree(id, null);
	}

	@Override
	public Function tree(Long id, Long siteGroupId, int... depths) {
		return functionDao.tree(id, siteGroupId, depths);
	}
	@Override
	public Function tree(Long id, int... depths) {
		return functionDao.tree(id, depths);
	}

	@Override
	public ResultSearchResult<Function> search(Long siteGroupId,
			SearchArgumentSupport argumentSupport) {
		Map<String, Object> params = new HashMap<String, Object>(3);
		params.put("siteGroupId", siteGroupId);
		return functionDao.search(params, argumentSupport);
	}
	
	public void setFunctionDao(FunctionDao functionDao) {
		this.functionDao = functionDao;
	}
}
